package cn.edu.service.impl;

import cn.edu.dao.dep_InfomationDao;
import cn.edu.domain.All;
import cn.edu.domain.InfoPageBean;
import cn.edu.domain.PieData;
import cn.edu.service.dep_InfomationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Davey chan
 */
@Service
public  class dep_InfomationServiceImpl implements dep_InfomationService {
    @Autowired
 private dep_InfomationDao infomationDao;

    @Override
    public InfoPageBean<All> infoselect(int currentPage, int pageSize, All t) {
        int begin=(currentPage-1)*pageSize;
//        计算查询的条目数
        int size =pageSize;
//        处理查询条件，模糊查询
        String title = t.getTitle();
        if(title !=null && title.length()>0){
            t.setTitle("%"+title+"%");

        }
        String Researchdir=t.getResearchdir();
        if(Researchdir != null && Researchdir.length()>0){
            t.setResearchdir("%"+Researchdir+"%");
        }
        String Tutor=t.getTutor();
        if(Tutor != null && Tutor.length()>0){
            t.setTutor("%"+Tutor+"%");
        }
        String endTime = t.getEndTime();
        if(endTime != null && endTime.length()>0){
            t.setEndTime("%"+endTime+"%");
        }
        t.setExamstatus("3");
        t.setExamstatus("3");
//        查询当前页的数据
        List<All> rows = infomationDao.Infoselect(begin, size,t);
//        查询总记录数
        int totalCount = infomationDao.selectTotalCountByCondition(t);
//封装pageBean
        InfoPageBean<All> infopageBean=new InfoPageBean<>();
        infopageBean.setRows(rows);
        infopageBean.setTotalCount(totalCount);
        return infopageBean;
    }

    @Override
    public List<PieData> getpie() {

        List<PieData> pieData=new ArrayList<>();
        PieData a=new PieData();
        int num1=infomationDao.GetprofessorNum();
        a.setValue(num1);
        a.setName("教授");
        pieData.add(a);
        PieData b=new PieData();
        int num2=infomationDao.GetAsprofessorNum();
        b.setValue(num2);
        b.setName("副教授");
        pieData.add(b);
        PieData c=new PieData();
        int num3=infomationDao.GetLecturerNum();
        c.setValue(num3);
        c.setName("讲师");
        pieData.add(c);
        return pieData;
    }

    @Override
    public List<Integer> getBar3() {
        List<Integer> barData=new ArrayList<>();
        int a=infomationDao.GetOpsNum();
        int b=infomationDao.GetPatentNum();
        int d=infomationDao.GetthesisNum();
       barData.add(a);
       barData.add(b);
       barData.add(d);
        return barData;
    }

    @Override
    public List getBar1() {
        List<Integer> barData=new ArrayList<>();
        int e=infomationDao.GetExcellent();
        int f=infomationDao.GetGood();
        int g=infomationDao.GetNormal();
        barData.add(e);
        barData.add(f);
        barData.add(g);
        return barData;
    }

    @Override
    public List getBar2() {
        List<Integer> barData=new ArrayList<>();
        int c=infomationDao.Getresearch_projectNum();
        barData.add(c);
        int h=infomationDao.GetAward();
        barData.add(h);
        return barData;
    }
}
